package com.sismul.activity;

import com.sismul.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;

 public class SplashScreen extends Activity {

	long m_dwSplashTime = 3000;
	//long m_dwSplashTime = 0;
	boolean m_bPaused = false;

	boolean m_bSplashActive = true;
	
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);
		// Draw the splash screen
        setContentView(R.layout.splashscreen);
        Thread splashTimer = new Thread() {
			public void run() {
				try {
					// Wait loop
					long ms = 0;
					while (m_bSplashActive && ms < m_dwSplashTime) {
						sleep(100);
						// Advance the timer only if we're running.
						if (!m_bPaused)
							ms += 100;
					}
				} catch (Exception e) {
					
				} finally {
					startActivity(new Intent("com.sismul.activity.HOMESCREEN"));
					finish();
				}
			}
		};
		splashTimer.start();
	}

	protected void onPause() {
		super.onPause();
		m_bPaused = true;
	}

	protected void onResume() {
		super.onResume();
		m_bPaused = false;
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// if we get any key, clear the splash screen
		super.onKeyDown(keyCode, event);
		m_bSplashActive = false;
		return true;
	}
	
	public boolean onTouchEvent(MotionEvent event) {
		// if we get any key, clear the splash screen
		super.onTouchEvent(event);
		m_bSplashActive = false;
		return true;
	}
	
}
